package com.bsoft.ecommerce.advice;

import cn.hutool.http.server.HttpServerRequest;
import com.bsoft.ecommerce.vo.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionAdvice {
    @ExceptionHandler(value = Exception.class)
    public CommonResponse<String> handlerCommerceExection(HttpServerRequest req, Exception e) {
        CommonResponse<String> response = new CommonResponse<>(-1, "business error ");
        response.setData(e.getMessage());
        log.error("commerce service has error [{}]", e.getMessage(), e);
        return response;
    }
}
